import java.util.HashMap;

/*
It's expected that you will customize your encounter.  Party and Combatant
classes shouldn't need to be modified

--note:  I really don't like this structure.  This is completely inelegant
  This object will need serious revisiting.
*/

/*
	TODO:
	* healing mechanism
	* Initiative (may require some new collection interface for multiple 
		combatants of a common type (ie: 3 identical orcs who would resolve 
		together)
	* Move initialization out to some more logical component (perhaps in the host
		class (ie: encountersim)
*/
class Encounter
{
	private Party Adventurers = new Party();
	private Party Monsters = new Party();
	// insert some mechanism for initiative here
	// probably a sorted list with custom comparator is best
	//Map Initiative;
	public Encounter()
	{
		//Initiative = new HashMap();
	}
	public void InitializeParty()
	{
		Combatant Spike = new Combatant("Spike",20,20,20,20,35);
		Action aPreciseStrike = new Action(5,15,0,8);
		Spike.AddAtWill(aPreciseStrike);
		Adventurers.AddMember(Spike);
	}
	public void InitializeMonsters()
	{
		Action aOrcAttack = new Action(1,8,0,4);
		Combatant Orc1 = new Combatant("Orc1",15,15,15,15,35);
		Combatant Orc2 = new Combatant("Orc2",15,15,15,15,35);
		Orc1.AddAtWill(aOrcAttack);
		Orc2.AddAtWill(aOrcAttack);
		Monsters.AddMember(Orc1);
		Monsters.AddMember(Orc2);
		Combatant bar =  Monsters.GetRandMember();
		System.out.println(bar.GetName());
	}
	public void ResolveCombat()
	{
		int iTurns = 0;
		// verify that there are combatants left standing
		while(Adventurers.Undefeated() && Monsters.Undefeated())
		{
			// determine initiative
			// no initiative for now
			// foreach combatant
			//    determine who it is attacking
			//    have it attack
			iTurns++;
			for(int i = 0; i < Adventurers.CombatantsLeft(); i++)
			{
				Combatant unit =  Adventurers.GetMember(i);
				Combatant target = Monsters.GetRandMember();
				unit.Attack(target);
			}
			for(int i = 0; i < Monsters.CombatantsLeft(); i++)
			{
				Combatant unit =  Monsters.GetMember(i);
				Combatant target = Adventurers.GetRandMember();
				unit.Attack(target);
			}
		}
		if(Adventurers.Undefeated())
		{
			System.out.println("Adventurers Win!");
		}
		else
		{
			System.out.println("Monsters Win!");
		}
		System.out.println("Turns Required: " + iTurns);
	}
}
